const fs = require('fs')
const path = require('path')
const faker = require('faker')
const mime = require('mime-types')
const walkSync = (dir, filelist = [], exclude = []) => {
  const files = fs.readdirSync(dir) || []
  filelist = filelist || []
  files.forEach((name) => {
    const filePath = path.join(dir, name)
    let file = {}
    const fileStat = fs.statSync(filePath)
    const fullPath = path.resolve(filePath)
    const parse = path.parse(filePath)
    const fileType = mime.lookup(filePath)
    if (fileStat.isDirectory()) {
      filelist = walkSync(filePath, filelist)
    } else {
      file = {
        uuid: faker.random.uuid(),
        fileName: name,
        fileType: fileType,
        path: filePath,
        fullPath: fullPath,
        ext: parse.ext,
        dir: parse.dir,
        ctime: fileStat.ctime,
        size: fileStat.size
      }
      filelist.push(file)
    }
  })
  return filelist
}
const files = walkSync('./static', [], [])

module.exports = () => {
  return {
    data: files
  }
}
